package com.kepler.social.common.constants;

import com.kepler.social.common.utils.ReflectionUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * UserEmailStateEnum 和 UserMobilePhoneStateEnum 两个枚举是一样的，但是业务不同。邮件，只能自己重新启用，手机可以被别人使用
 */
public class Enums {

    @Getter
    @AllArgsConstructor
    public enum UserFeatureEnum {
        avatar("avatar", "avatar", "头像", String.class),
        bgImage("bgImage", "bgImage", "主页背景图片", String.class),
        nickName("nickName", "nickName", "昵称", String.class),
        gender("gender", "gender", "性别", Integer.class),
        account("account", "account", "账号", String.class),
        birthday("birthday", "birthday", "生日", Long.class),
        profile("profile", "profile", "个人简介", String.class),
        ;
        public String code;
        public String dbField;
        public String name;
        public Class clazz;

        public static UserFeatureEnum getByType(String code) {
            for (UserFeatureEnum enum_ : values()) {
                if (enum_.getCode().equals(code)) {
                    return enum_;
                }
            }
            return null;
        }

        public static String getNameByType(String code) {
            UserFeatureEnum _enum = getByType(code);
            return Objects.isNull(_enum) ? null : _enum.name;
        }

        public <T> T convert(String value) {
            return (T) ReflectionUtil.convertClass(clazz, value);
        }
    }

    @Getter
    @AllArgsConstructor
    public enum UserEmailStateEnum {
        NOT_VERIFIED(0, "未验证"),
        USED(1, "使用中"),
        DISUSED(2, "已废弃");
        public int code;
        public String name;

        public static UserEmailStateEnum getByType(int type) {
            for (UserEmailStateEnum enum_ : values()) {
                if (enum_.getCode() == type) {
                    return enum_;
                }
            }
            return null;
        }

        public static String getNameByType(int type) {
            UserEmailStateEnum _enum = getByType(type);
            return Objects.isNull(_enum) ? null : _enum.name;
        }
    }

    @Getter
    @AllArgsConstructor
    public enum UserMobilePhoneStateEnum {
        NOT_VERIFIED(0, "未验证"),
        USED(1, "使用中"),
        DISUSED(2, "已废弃");
        public int code;
        public String name;

        public static UserMobilePhoneStateEnum getByType(int type) {
            for (UserMobilePhoneStateEnum enum_ : values()) {
                if (enum_.getCode() == type) {
                    return enum_;
                }
            }
            return null;
        }

        public static String getNameByType(int type) {
            UserMobilePhoneStateEnum _enum = getByType(type);
            return Objects.isNull(_enum) ? null : _enum.name;
        }
    }

    @Getter
    @AllArgsConstructor
    public enum TargetEnum {
        MOBILE_PHONE(1, "手机"),
        EMAIL(2, "电子邮件"),
        ;
        public int code;
        public String name;
    }

    @Getter
    @AllArgsConstructor
    public enum LoginMethodEnum {
        MOBILE_PHONE(1, "手机"),
        EMAIL(2, "电子邮件"),
        ;
        public int code;
        public String name;
    }


    @Getter
    @AllArgsConstructor
    public enum GenderEnum {
        Unknown(0, "未知"),
        Male(1, "男"),
        Female(2, "女"),
        Other(2, "其他");
        public int code;
        public String name;

        public static GenderEnum getByType(int type) {
            for (GenderEnum enum_ : values()) {
                if (enum_.getCode() == type) {
                    return enum_;
                }
            }
            return null;
        }

        public static String getNameByType(int type) {
            GenderEnum _enum = getByType(type);
            return Objects.isNull(_enum) ? null : _enum.name;
        }
    }

    @Getter
    @AllArgsConstructor
    public enum DataTypeEnum {
        String("string", "字符串"),
        Int("int", "整型"),
        Long("long", "长整型"),
        ;
        public String type;
        public String name;

        public static DataTypeEnum getByType(String type) {
            for (DataTypeEnum enum_ : values()) {
                if (enum_.getType().equals(type)) {
                    return enum_;
                }
            }
            return null;
        }

        public static String getNameByType(String type) {
            DataTypeEnum _enum = getByType(type);
            return Objects.isNull(_enum) ? null : _enum.name;
        }
    }

}
